<%@ page language="java" contentType="text/html; charset=UTF-8"%>
<%-- 引入页面头 --%>
<%@ include file="/pageHead.jsp"%>

<form name="form1" id="form1" action="" method="post">
	<div class="pageMain">
		<div class="pageTitle">
			<%=MessageResourcesUtils.getMessage(request, "systemmanage.bascsetting.title")%>
			<span></span>
			<%=MessageResourcesUtils.getMessage(request, "systemmanage.preferential") %>
			<span></span>
			<%=MessageResourcesUtils.getMessage(request, "systemmanage.preferential.add") %>
		</div>
		<div class="pageBody">
			<div class="form-group">
				<ul> 
					<li>
						<i>*</i>
						<label>
							<%=MessageResourcesUtils.getMessage(request,"systemmanage.preferential.column.preferentialType")%>
						</label>
						<span><select id="preferentialType" name="preferentialType" class="validate[required]" onchange="changePreferentialType()"></select></span> 
					</li>				
				</ul>
				<ul>
					<li>
						<i>*</i>
						<label>
							<%=MessageResourcesUtils.getMessage(request,"systemmanage.preferential.column.channel")%>
						</label>
						<span>
							<select id="channel" name="channel" class="validate[required]">
								<option value="">
									<%=MessageResourcesUtils.getMessage(request, "systemmanage.preferential.select.select") %>
								</option>
								<c:forEach items="${channelList}" var="channel">
									<option value="${channel.value}">${channel.dataContent}</option>
								</c:forEach>
							</select>
						</span>  
					</li>
				</ul>
				<ul>
					<li>
						<i>*</i>
						<label>
							<%=MessageResourcesUtils.getMessage(request,"systemmanage.preferential.column.medium")%>
						</label>
						<span>
							<select id="medium" name="medium" class="validate[required]">
								<option value="">
									<%=MessageResourcesUtils.getMessage(request, "systemmanage.preferential.select.select") %>
								</option>
								<c:forEach items="${mediumList}" var="medium">
									<option value="${medium.value}">${medium.dataContent}</option>
								</c:forEach>
							</select>
						</span> 
					</li>
				</ul>		
				<ul>
					<li>
						<i>*</i>
						<label><%=MessageResourcesUtils.getMessage(request, "systemmanage.preferential.label.num") %></label>
						<span><input type="text" id="num" name="num" maxlength="3" size="22" class="validate[required,custom[integer]]"/></span>
					</li>
				</ul>
				<ul>
					<li>
						<i>*</i>
						<label><%=MessageResourcesUtils.getMessage(request, "systemmanage.preferential.label.time") %></label>
						<span><input type="text" id="maxLimit" name="maxLimit" class="validate[required,custom[integer]]"/></span>
						<span id="maxLimitDay" style="display: none;">天</span>
						<span id="maxLimitHour" style="display: none;">分钟</span>
					</li>
				</ul>
			</div>		
        	<div class="button-group">
       			<input type="button" class="btn btn-default"  id="butSave" name="butSave" value='<%=MessageResourcesUtils.getMessage(request, "common.button.save") %>' />
       			<input type="button" class="btn btn-default"  id="butReturn" name="butReturn" value='<%=MessageResourcesUtils.getMessage(request, "common.button.back") %>' />
			</div>
			<div id="resultDiv" style="display: none;">
				<div><%=MessageResourcesUtils.getMessage(request, "systemmanage.preferential.tip") %></div>
                <div class="divRight">
                     <textarea id="result_textarea" rows="10" cols="100" readonly="readonly"></textarea>
                </div>
            </div>
		</div>
	</div>
</form>

<script type="text/javascript">	
$(document).ready(function() {
	changePreferentialType();
	$("#preferentialType").selectutil({
		optModel :<%=SysConstant.PreferentialType.getModelJSONString2(false, true)%>,
		optDefault :''
	});
	$('#butSave').click(function() {
		var exp = $('#form1').validationEngine('validate');

		if(exp==true)
		{
			// 显示进度条
			showSending();
			$.ajax({
				type: 'POST',
			    url: '${systemctx}/systemmanage/preferential/addPreferentialCode.json',
			    data: $("#form1").serialize(),
			    dataType: 'json',
			    success: function(data)
			    {
			    	//关闭执行...
					closeSending();
			    	if (data.messageType == 1)
			    	{
			    		var codeArr = data.preferentialCodeList;
    					$("#resultDiv").show();
    					for(var i in codeArr) {
    						$("#result_textarea").append(codeArr[i] + ";\n");
    					}
    					// 重置关键数据
    					$("#num").val("");
    					$("#maxLimit").val("");
			    		//显示AJAX请求后的提示信息
						$.fn.ajaxmessage(data);
			    	}
			    	else
			    	{
			    		//显示AJAX请求后的提示信息
						$.fn.ajaxmessage(data);
			    	}
			    }
			});
		}
	});
	
	$('#butReturn').click(function(){
		parent.document.location.reload();
	    $.fn.closeIssWindow();
	});
});

function changePreferentialType(){
	var thisData = $("#preferentialType").val();
	switch(thisData) {
	case "ExchangePermission_TL": 
		$("#maxLimitHour").hide();
		$("#maxLimitDay").show();
		break;
	case "ExchangeTimes": 
		$("#maxLimitDay").hide();
		$("#maxLimitHour").show();
		break;
	default: 
		$("#maxLimitDay").hide();
		$("#maxLimitHour").hide();
	}
}
</script>
<%-- 引入页面尾 --%>
<%@ include file="/pageFloor.jsp"%>